using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using sbMembership.Library.Domain;
using sbMembership.Library.Presenters;

namespace Tests.sbMembership.ListRoles
{
    [TestFixture]
    public class ListRolesTest
    {
        private MockListRolesView mockView;
        private ListRolesPresenter presenter;
        private bool addRoleEventRaised = false;
        private bool deleteRoleEventRaised = false;
        private bool editRoleEventRaised = false;

        [TestFixtureSetUp]
        public void Setup()
        {
            mockView = new MockListRolesView();
            presenter = new ListRolesPresenter(mockView);
            mockView.AttachPresenter(presenter);
        }

        [Test]
        public void InitView()
        {
            presenter.InitViewFor(ListRolesPresenter.ActionEnum.none);
            Assert.IsNotEmpty(mockView.Roles);
            Assert.IsNotEmpty(mockView.Message);
        }

        [Test]
        public void AddRoleRaisesEvent()
        {
            presenter.LaunchAddRoleEvent = new EventHandler(OnAddRoleEvent);
            presenter.LaunchAddRole();
            Assert.IsTrue(addRoleEventRaised);
        }

        void OnAddRoleEvent(object sender, EventArgs e)
        {
            addRoleEventRaised = true;
        }

        [Test]
        public void DeleteRole()
        {
            presenter.DeleteRoleCompleteEvent += new EventHandler(OnDeleteRoleCompleteEvent);
            presenter.DeleteRole(TestSetup.testDeleteRoleName);
            Assert.IsTrue(deleteRoleEventRaised);
        }

        void OnDeleteRoleCompleteEvent(object sender, EventArgs e)
        {
            deleteRoleEventRaised = true;
        }

        [Test]
        public void EditRoleRaisesEvent()
        {
            presenter.LaunchEditRoleEvent += new EventHandler(OnEditRoleEvent);
            presenter.LaunchEditRole(TestSetup.testRoleName);
            Assert.IsTrue(editRoleEventRaised);
        }

        void OnEditRoleEvent(object sender, EventArgs e)
        {
            editRoleEventRaised = true;
        }
    }
}
